const Koa = require('koa')
const fs = require('fs')
const app = new Koa()

const router = require('koa-router')()
const article=require('../../controller/articleController').getarticle //获取上线新闻
const getnavlist=require('../../controller/articleController').getNavigationList //获取上线楼层导航栏
// const coinlimt24 = require('../../controller/coincontroller').coinlimt24 //所有币种
const coinlimt24 = require('../../controller/materialController').huobicoinPrice   
const home = router.get('/', async (ctx) => { //主页
    let useragent = ctx.headers['user-agent'].toLowerCase()
    let ismobile = /(iphone|ipod|ipad|android)/.test(useragent)
    if (ismobile) {
        ctx.redirect('/m');
        ctx.status = 301
    }
    const articlelist=await article()
    const coinlimt=await coinlimt24()
//     const coinlimt=[{ symbol: 'ZIL',
//     data: 
//      { id: 1531238400,
//        open: 0.071303,
//        close: 0.067271,
//        low: 0.063136,
//        high: 0.071999,
//        amount: 48133944.65329078,
//        vol: 3244738.522862075,
//        count: 12714,
//        extent: 0.9761 } },
//   { symbol: 'STEEM',
//     data: 
//      { id: 1531238400,
//        open: 1.3494,
//        close: 1.2923,
//        low: 1.1916,
//        high: 1.3996,
//        amount: 221325.46011466335,
//        vol: 285872.97878434,
//        count: 9225,
//        extent: 3.7202 } },
//   { symbol: 'GNT', data: null },
//   { symbol: 'HSR', data: null },
//   { symbol: 'IOST',
//     data: 
//      { id: 1531238400,
//        open: 0.021433,
//        close: 0.01984,
//        low: 0.0188,
//        high: 0.021547,
//        amount: 313821871.43883634,
//        vol: 6312789.269924255,
//        count: 20298,
//        extent: 0.5319 } },
//   { symbol: 'WICC',
//     data: 
//      { id: 1531238400,
//        open: 0.4228,
//        close: 0.3964,
//        low: 0.3791,
//        high: 0.424,
//        amount: 2422794.419201498,
//        vol: 967492.2587489199,
//        count: 12345,
//        extent: 0.2838 } },
//   { symbol: 'SOC', data: null } ]
    await ctx.render('home', {
        coinlimt,
        articlelist
    })
})

const mhome = router.get('/m', async (ctx) => { //主页
    let useragent = ctx.headers['user-agent'].toLowerCase()
    let ismobile = /(iphone|ipod|ipad|android)/.test(useragent)
    const articlelist=await article()
    // if(/(micromessenger)/.test(useragent)){
    //     ctx.redirect(`http://jsmijijia.cn/m`);
    //     ctx.status = 301
    // }
    if (!ismobile) {
        ctx.redirect('/');
        ctx.status = 301
    }
    const coinlimt=await coinlimt24()
    await ctx.render('mhome', {
        coinlimt,
        articlelist
    })
})
const mcoinmore = router.get('/m/coinmore', async (ctx) => { //更多行情
    const coinlimt=await coinlimt24()

    await ctx.render('mcoinmore', {
        coinlimt
    })
})

const mnavigation=router.get('/m/mnavigation', async ( ctx )=>{ //导航
    const coinlimt=await coinlimt24()
    const articlelist=await article()
    await ctx.render('mnavigation',{
    coinlimt,
    articlelist
    })
    })

const mychoice = router.get('/m/mychoice', async (ctx) => { //自选
    const coinlimt = await coinlimt24()
    await ctx.render('mychoice', {
        coinlimt
    })
})
const mloading = router.get('/m/mloading', async (ctx) => { //主页
    const coinlimt = await coinlimt24()
    await ctx.render('mloading', {
        coinlimt
    })
})
const mregistered = router.get('/m/mregistered', async (ctx) => { //注册
    const coinlimt = await coinlimt24()
    await ctx.render('mregistered', {
        coinlimt
    })
})
const forget = router.get('/m/forget', async (ctx) => { //注册
    const coinlimt = await coinlimt24()
    await ctx.render('forget', {
        coinlimt
    })
})
const maddoptional = router.get('/m/maddoptional', async (ctx) => { //我的自选
    const coinlimt = await coinlimt24()
    const getnav = await getnavlist()
    const articlelist = await article()
    // const usergetnavlis=await usergetnavlist()
    await ctx.render('maddoptional', {
        coinlimt,
        getnav,
        articlelist,
        // usergetnavlis
    })
})

const wxtext = router.get('/MP_verify_422xUSYt1071UAUK.txt',async (ctx) => { //微信公众号认证
    ctx.body='422xUSYt1071UAUK'
})

module.exports = router